from collections import defaultdict
from skidl import Pin, Part, Alias, SchLib, SKIDL, TEMPLATE

from skidl.pin import pin_types

SKIDL_lib_version = '0.0.1'

MCU_Microchip_SAMA = SchLib(tool=SKIDL).add_parts(*[
        Part(**{ 'name':'ATSAMA5D21', 'dest':TEMPLATE, 'tool':SKIDL, 'aliases':Alias({'ATSAMA5D21'}), 'ref_prefix':'U', 'fplist':['Package_BGA:Microchip_TFBGA-196_11x11mm_Layout14x14_P0.75mm_SMD'], 'footprint':'Package_BGA:Microchip_TFBGA-196_11x11mm_Layout14x14_P0.75mm_SMD', 'keywords':'MPU Cortex-A5 Cortex A5 Linux DDR DRAM BGA', 'description':'', 'datasheet':'http://ww1.microchip.com/downloads/en/DeviceDoc/SAMA5D2-Series-Data-Sheet-DS60001476C.pdf', 'search_text':'/usr/share/kicad/symbols/MCU_Microchip_SAMA.kicad_sym\nATSAMA5D21\n\nMPU Cortex-A5 Cortex A5 Linux DDR DRAM BGA', 'pins':[
            Pin(num='L10',name='PA25',func=pin_types.BIDIR,unit=1),
            Pin(num='L9',name='PA18',func=pin_types.BIDIR,unit=1),
            Pin(num='M10',name='PA21',func=pin_types.BIDIR,unit=1),
            Pin(num='M11',name='PA28',func=pin_types.BIDIR,unit=1),
            Pin(num='M12',name='PA31',func=pin_types.BIDIR,unit=1),
            Pin(num='M9',name='PA20',func=pin_types.BIDIR,unit=1),
            Pin(num='N10',name='PA24',func=pin_types.BIDIR,unit=1),
            Pin(num='N11',name='PA29',func=pin_types.BIDIR,unit=1),
            Pin(num='N12',name='PA30',func=pin_types.BIDIR,unit=1),
            Pin(num='N9',name='PA19',func=pin_types.BIDIR,unit=1),
            Pin(num='P10',name='PA23',func=pin_types.BIDIR,unit=1),
            Pin(num='P11',name='PA26',func=pin_types.BIDIR,unit=1),
            Pin(num='P12',name='PA27',func=pin_types.BIDIR,unit=1),
            Pin(num='P9',name='PA22',func=pin_types.BIDIR,unit=1),
            Pin(num='A1',name='PB10',func=pin_types.BIDIR,unit=2),
            Pin(num='A2',name='PB8',func=pin_types.BIDIR,unit=2),
            Pin(num='A3',name='PB6',func=pin_types.BIDIR,unit=2),
            Pin(num='A4',name='PB4',func=pin_types.BIDIR,unit=2),
            Pin(num='A5',name='PB1',func=pin_types.BIDIR,unit=2),
            Pin(num='A6',name='PB0',func=pin_types.BIDIR,unit=2),
            Pin(num='B1',name='PB11',func=pin_types.BIDIR,unit=2),
            Pin(num='B2',name='PB12',func=pin_types.BIDIR,unit=2),
            Pin(num='B3',name='PB9',func=pin_types.BIDIR,unit=2),
            Pin(num='B4',name='PB7',func=pin_types.BIDIR,unit=2),
            Pin(num='B5',name='PB3',func=pin_types.BIDIR,unit=2),
            Pin(num='B6',name='PB2',func=pin_types.BIDIR,unit=2),
            Pin(num='C1',name='PB13',func=pin_types.BIDIR,unit=2),
            Pin(num='C2',name='PB17',func=pin_types.BIDIR,unit=2),
            Pin(num='C3',name='PB20',func=pin_types.BIDIR,unit=2),
            Pin(num='C4',name='PB19',func=pin_types.BIDIR,unit=2),
            Pin(num='C5',name='PB16',func=pin_types.BIDIR,unit=2),
            Pin(num='D1',name='PB21',func=pin_types.BIDIR,unit=2),
            Pin(num='D2',name='PB22',func=pin_types.BIDIR,unit=2),
            Pin(num='D3',name='PB24',func=pin_types.BIDIR,unit=2),
            Pin(num='D4',name='PB18',func=pin_types.BIDIR,unit=2),
            Pin(num='D5',name='PB14',func=pin_types.BIDIR,unit=2),
            Pin(num='D6',name='PB5',func=pin_types.BIDIR,unit=2),
            Pin(num='E1',name='PB23',func=pin_types.BIDIR,unit=2),
            Pin(num='E2',name='PB26',func=pin_types.BIDIR,unit=2),
            Pin(num='E3',name='PB25',func=pin_types.BIDIR,unit=2),
            Pin(num='E5',name='PB15',func=pin_types.BIDIR,unit=2),
            Pin(num='E6',name='PB27',func=pin_types.BIDIR,unit=2),
            Pin(num='F1',name='PB28',func=pin_types.BIDIR,unit=2),
            Pin(num='F2',name='PB30',func=pin_types.BIDIR,unit=2),
            Pin(num='F6',name='PB29',func=pin_types.BIDIR,unit=2),
            Pin(num='F7',name='PB31',func=pin_types.BIDIR,unit=2),
            Pin(num='J8',name='PC5',func=pin_types.BIDIR,unit=3),
            Pin(num='J9',name='PC8',func=pin_types.BIDIR,unit=3),
            Pin(num='K10',name='PC3',func=pin_types.BIDIR,unit=3),
            Pin(num='M13',name='PC0',func=pin_types.BIDIR,unit=3),
            Pin(num='M14',name='PC7',func=pin_types.BIDIR,unit=3),
            Pin(num='N13',name='PC2',func=pin_types.BIDIR,unit=3),
            Pin(num='N14',name='PC6',func=pin_types.BIDIR,unit=3),
            Pin(num='P13',name='PC1',func=pin_types.BIDIR,unit=3),
            Pin(num='P14',name='PC4',func=pin_types.BIDIR,unit=3),
            Pin(num='F3',name='PD8',func=pin_types.BIDIR,unit=4),
            Pin(num='F5',name='PD7',func=pin_types.BIDIR,unit=4),
            Pin(num='G1',name='PD16',func=pin_types.BIDIR,unit=4),
            Pin(num='G2',name='PD17',func=pin_types.BIDIR,unit=4),
            Pin(num='G3',name='PD18',func=pin_types.BIDIR,unit=4),
            Pin(num='G4',name='PD10',func=pin_types.BIDIR,unit=4),
            Pin(num='G5',name='PD9',func=pin_types.BIDIR,unit=4),
            Pin(num='G6',name='PD14',func=pin_types.BIDIR,unit=4),
            Pin(num='H1',name='PD11',func=pin_types.BIDIR,unit=4),
            Pin(num='H3',name='PD13',func=pin_types.BIDIR,unit=4),
            Pin(num='H4',name='PD19',func=pin_types.BIDIR,unit=4),
            Pin(num='H5',name='PD15',func=pin_types.BIDIR,unit=4),
            Pin(num='H6',name='PD12',func=pin_types.BIDIR,unit=4),
            Pin(num='J1',name='PD20',func=pin_types.BIDIR,unit=4),
            Pin(num='J3',name='PD22',func=pin_types.BIDIR,unit=4),
            Pin(num='K1',name='PD21',func=pin_types.BIDIR,unit=4),
            Pin(num='K2',name='PD23',func=pin_types.BIDIR,unit=4),
            Pin(num='D7',name='VDDIOP0',func=pin_types.PWRIN,unit=5),
            Pin(num='E4',name='GNDIOP0',func=pin_types.PWRIN,unit=5),
            Pin(num='E7',name='GNDIOP0',func=pin_types.PASSIVE,unit=5),
            Pin(num='E8',name='VDDCORE',func=pin_types.PWRIN,unit=5),
            Pin(num='F4',name='VDDIOP0',func=pin_types.PASSIVE,unit=5),
            Pin(num='F8',name='GNDCORE',func=pin_types.PWRIN,unit=5),
            Pin(num='G7',name='GNDCORE',func=pin_types.PASSIVE,unit=5),
            Pin(num='G8',name='VDDCORE',func=pin_types.PASSIVE,unit=5),
            Pin(num='G9',name='GNDCORE',func=pin_types.PASSIVE,unit=5),
            Pin(num='H2',name='VDDANA',func=pin_types.PASSIVE,unit=5),
            Pin(num='H7',name='GNDCORE',func=pin_types.PASSIVE,unit=5),
            Pin(num='H8',name='VDDCORE',func=pin_types.PASSIVE,unit=5),
            Pin(num='H9',name='VDDCORE',func=pin_types.PASSIVE,unit=5),
            Pin(num='J2',name='GNDANA',func=pin_types.PASSIVE,unit=5),
            Pin(num='J4',name='GNDCORE',func=pin_types.PASSIVE,unit=5),
            Pin(num='J5',name='VDDCORE',func=pin_types.PASSIVE,unit=5),
            Pin(num='K3',name='VDDANA',func=pin_types.PWRIN,unit=5),
            Pin(num='K4',name='GNDANA',func=pin_types.PWRIN,unit=5),
            Pin(num='K8',name='VDDIOP1',func=pin_types.PWRIN,unit=5),
            Pin(num='K9',name='GNDIOP1',func=pin_types.PWRIN,unit=5),
            Pin(num='L11',name='VDDIOP1',func=pin_types.PASSIVE,unit=5),
            Pin(num='L12',name='GNDIOP1',func=pin_types.PASSIVE,unit=5),
            Pin(num='L2',name='ADVREF',func=pin_types.PWRIN,unit=5),
            Pin(num='L6',name='GNDDPLL',func=pin_types.PWRIN,unit=5),
            Pin(num='P3',name='VDDPLLA',func=pin_types.PWRIN,unit=5),
            Pin(num='P4',name='GNDPLLA',func=pin_types.PWRIN,unit=5),
            Pin(num='A10',name='DDR_D6',func=pin_types.BIDIR,unit=6),
            Pin(num='A11',name='DDR_A11',func=pin_types.OUTPUT,unit=6),
            Pin(num='A12',name='DDR_A3',func=pin_types.OUTPUT,unit=6),
            Pin(num='A13',name='DDR_CLK',func=pin_types.OUTPUT,unit=6),
            Pin(num='A14',name='DDR_WE',func=pin_types.OUTPUT,unit=6),
            Pin(num='A7',name='DDR_D1',func=pin_types.BIDIR,unit=6),
            Pin(num='A8',name='DDR_DQSN0',func=pin_types.OUTPUT,unit=6),
            Pin(num='A9',name='DDR_D4',func=pin_types.BIDIR,unit=6),
            Pin(num='B10',name='DDR_D7',func=pin_types.BIDIR,unit=6),
            Pin(num='B11',name='DDR_A12',func=pin_types.OUTPUT,unit=6),
            Pin(num='B12',name='DDR_A2',func=pin_types.OUTPUT,unit=6),
            Pin(num='B13',name='DDR_CLKN',func=pin_types.OUTPUT,unit=6),
            Pin(num='B14',name='DDR_A6',func=pin_types.OUTPUT,unit=6),
            Pin(num='B7',name='DDR_D0',func=pin_types.BIDIR,unit=6),
            Pin(num='B8',name='DDR_DQS0',func=pin_types.OUTPUT,unit=6),
            Pin(num='B9',name='DDR_D3',func=pin_types.BIDIR,unit=6),
            Pin(num='C10',name='DDR_A8',func=pin_types.OUTPUT,unit=6),
            Pin(num='C11',name='DDR_A1',func=pin_types.OUTPUT,unit=6),
            Pin(num='C12',name='DDR_VREF',func=pin_types.PWRIN,unit=6),
            Pin(num='C13',name='DDR_CAS',func=pin_types.OUTPUT,unit=6),
            Pin(num='C14',name='DDR_RAS',func=pin_types.OUTPUT,unit=6),
            Pin(num='C6',name='VDDIODDR',func=pin_types.PWRIN,unit=6),
            Pin(num='C7',name='GNDIODDR',func=pin_types.PWRIN,unit=6),
            Pin(num='C8',name='DDR_D2',func=pin_types.BIDIR,unit=6),
            Pin(num='C9',name='DDR_D5',func=pin_types.BIDIR,unit=6),
            Pin(num='D10',name='DDR_A9',func=pin_types.OUTPUT,unit=6),
            Pin(num='D11',name='DDR_A4',func=pin_types.OUTPUT,unit=6),
            Pin(num='D12',name='GNDIODDR',func=pin_types.PASSIVE,unit=6),
            Pin(num='D13',name='~{DDR_RESET}',func=pin_types.OUTPUT,unit=6),
            Pin(num='D14',name='DDR_A5',func=pin_types.OUTPUT,unit=6),
            Pin(num='D8',name='DDR_DQM0',func=pin_types.OUTPUT,unit=6),
            Pin(num='D9',name='DDR_A7',func=pin_types.OUTPUT,unit=6),
            Pin(num='E10',name='VDDIODDR',func=pin_types.PASSIVE,unit=6),
            Pin(num='E11',name='DDR_A0',func=pin_types.OUTPUT,unit=6),
            Pin(num='E12',name='VDDIODDR',func=pin_types.PASSIVE,unit=6),
            Pin(num='E13',name='DDR_A13',func=pin_types.OUTPUT,unit=6),
            Pin(num='E14',name='DDR_CKE',func=pin_types.OUTPUT,unit=6),
            Pin(num='E9',name='GNDIODDR',func=pin_types.PASSIVE,unit=6),
            Pin(num='F10',name='DDR_CAL',func=pin_types.INPUT,unit=6),
            Pin(num='F11',name='DDR_CS',func=pin_types.OUTPUT,unit=6),
            Pin(num='F12',name='GNDIODDR',func=pin_types.PASSIVE,unit=6),
            Pin(num='F13',name='DDR_BA0',func=pin_types.OUTPUT,unit=6),
            Pin(num='F14',name='DDR_BA2',func=pin_types.OUTPUT,unit=6),
            Pin(num='F9',name='DDR_A10',func=pin_types.OUTPUT,unit=6),
            Pin(num='G10',name='VDDIODDR',func=pin_types.PASSIVE,unit=6),
            Pin(num='G11',name='GNDIODDR',func=pin_types.PASSIVE,unit=6),
            Pin(num='G12',name='VDDIODDR',func=pin_types.PASSIVE,unit=6),
            Pin(num='G13',name='DDR_BA1',func=pin_types.OUTPUT,unit=6),
            Pin(num='G14',name='DDR_DQM1',func=pin_types.OUTPUT,unit=6),
            Pin(num='H10',name='GNDIODDR',func=pin_types.PASSIVE,unit=6),
            Pin(num='H11',name='VDDIODDR',func=pin_types.PASSIVE,unit=6),
            Pin(num='H12',name='DDR_VREF',func=pin_types.PASSIVE,unit=6),
            Pin(num='H13',name='DDR_D8',func=pin_types.BIDIR,unit=6),
            Pin(num='H14',name='DDR_D9',func=pin_types.BIDIR,unit=6),
            Pin(num='J10',name='VDDIODDR',func=pin_types.PASSIVE,unit=6),
            Pin(num='J11',name='GNDIODDR',func=pin_types.PASSIVE,unit=6),
            Pin(num='J12',name='DDR_D14',func=pin_types.BIDIR,unit=6),
            Pin(num='J13',name='DDR_D10',func=pin_types.BIDIR,unit=6),
            Pin(num='J14',name='DDR_D11',func=pin_types.BIDIR,unit=6),
            Pin(num='K12',name='DDR_D15',func=pin_types.BIDIR,unit=6),
            Pin(num='K13',name='DDR_DQSN1',func=pin_types.OUTPUT,unit=6),
            Pin(num='K14',name='DDR_DQS1',func=pin_types.OUTPUT,unit=6),
            Pin(num='L13',name='DDR_D12',func=pin_types.BIDIR,unit=6),
            Pin(num='L14',name='DDR_D13',func=pin_types.BIDIR,unit=6),
            Pin(num='K11',name='VDDFUSE',func=pin_types.PWRIN,unit=7),
            Pin(num='K7',name='VDDUTMII',func=pin_types.PWRIN,unit=7),
            Pin(num='L7',name='VBG',func=pin_types.PWRIN,unit=7),
            Pin(num='L8',name='GNDUTMII',func=pin_types.PWRIN,unit=7),
            Pin(num='M7',name='VDDUTMIC',func=pin_types.PWRIN,unit=7),
            Pin(num='M8',name='GNDUTMIC',func=pin_types.PWRIN,unit=7),
            Pin(num='N7',name='HHSDPA',func=pin_types.BIDIR,unit=7),
            Pin(num='N8',name='HHSDPB',func=pin_types.BIDIR,unit=7),
            Pin(num='P7',name='HHSDMA',func=pin_types.BIDIR,unit=7),
            Pin(num='P8',name='HHSDMB',func=pin_types.BIDIR,unit=7),
            Pin(num='K5',name='PIOBU0',func=pin_types.BIDIR,unit=8),
            Pin(num='L1',name='XOUT32',func=pin_types.OUTPUT,unit=8),
            Pin(num='L3',name='PIOBU1',func=pin_types.BIDIR,unit=8),
            Pin(num='L4',name='JTAGSEL',func=pin_types.INPUT,unit=8),
            Pin(num='L5',name='PIOBU4',func=pin_types.BIDIR,unit=8),
            Pin(num='M1',name='XIN32',func=pin_types.INPUT,unit=8),
            Pin(num='M2',name='TST',func=pin_types.INPUT,unit=8),
            Pin(num='M3',name='PIOBU2',func=pin_types.BIDIR,unit=8),
            Pin(num='M4',name='VDDBU',func=pin_types.PWRIN,unit=8),
            Pin(num='M5',name='GNDBU',func=pin_types.PWRIN,unit=8),
            Pin(num='M6',name='PIOBU5',func=pin_types.BIDIR,unit=8),
            Pin(num='N1',name='SHDN',func=pin_types.OUTPUT,unit=8),
            Pin(num='N2',name='COMPP',func=pin_types.INPUT,unit=8),
            Pin(num='N3',name='~{RST}',func=pin_types.INPUT,unit=8),
            Pin(num='N4',name='PIOBU3',func=pin_types.BIDIR,unit=8),
            Pin(num='P1',name='WKUP',func=pin_types.INPUT,unit=8),
            Pin(num='P2',name='COMPN',func=pin_types.INPUT,unit=8),
            Pin(num='J6',name='GNDAUDIOPLL',func=pin_types.PWRIN,unit=9),
            Pin(num='J7',name='CLK_AUDIO',func=pin_types.OUTPUT,unit=9),
            Pin(num='K6',name='VDDAUDIOPLL',func=pin_types.PWRIN,unit=9),
            Pin(num='N5',name='VDDOSC',func=pin_types.PWRIN,unit=10),
            Pin(num='N6',name='GNDOSC',func=pin_types.PWRIN,unit=10),
            Pin(num='P5',name='XIN',func=pin_types.INPUT,unit=10),
            Pin(num='P6',name='XOUT',func=pin_types.OUTPUT,unit=10)], 'unit_defs':[{'label': 'uA', 'num': 1, 'pin_nums': ['L9', 'N12', 'N10', 'M12', 'M10', 'N9', 'P12', 'M11', 'P11', 'P9', 'M9', 'N11', 'L10', 'P10']},{'label': 'uB', 'num': 2, 'pin_nums': ['A3', 'B5', 'E5', 'B6', 'A4', 'D3', 'E6', 'A5', 'C1', 'D4', 'F1', 'A6', 'C2', 'D5', 'F2', 'B1', 'C3', 'D6', 'F6', 'B2', 'C4', 'E1', 'F7', 'A1', 'B3', 'C5', 'D2', 'E2', 'A2', 'B4', 'D1', 'E3']},{'label': 'uC', 'num': 3, 'pin_nums': ['J9', 'M13', 'N13', 'J8', 'K10', 'M14', 'N14', 'P14', 'P13']},{'label': 'uD', 'num': 4, 'pin_nums': ['G5', 'H1', 'H4', 'H6', 'J3', 'K2', 'F5', 'G2', 'G4', 'G6', 'H3', 'H5', 'J1', 'K1', 'F3', 'G1', 'G3']},{'label': 'uE', 'num': 5, 'pin_nums': ['G9', 'D7', 'K3', 'H2', 'E7', 'P3', 'E4', 'H7', 'K4', 'P4', 'H8', 'K8', 'F4', 'L11', 'E8', 'H9', 'K9', 'J2', 'L12', 'G7', 'F8', 'J4', 'L6', 'G8', 'J5', 'L2']},{'label': 'uF', 'num': 6, 'pin_nums': ['F10', 'J11', 'F12', 'L13', 'A7', 'B7', 'C6', 'D14', 'F11', 'G13', 'H10', 'L14', 'D8', 'C7', 'B8', 'A8', 'E10', 'G14', 'J12', 'B9', 'A9', 'C8', 'D9', 'F13', 'H11', 'J13', 'A14', 'A10', 'B10', 'C10', 'C14', 'C9', 'D13', 'E11', 'F14', 'H12', 'J14', 'G10', 'C11', 'A11', 'B11', 'D10', 'D12', 'E12', 'F9', 'K12', 'E13', 'B12', 'C12', 'A12', 'D11', 'E9', 'E14', 'G11', 'H13', 'K13', 'J10', 'A13', 'B13', 'C13', 'G12', 'H14', 'K14', 'B14']},{'label': 'uG', 'num': 7, 'pin_nums': ['K11', 'L7', 'M7', 'N7', 'P7', 'L8', 'M8', 'N8', 'P8', 'K7']},{'label': 'uH', 'num': 8, 'pin_nums': ['M3', 'L1', 'M5', 'L4', 'M1', 'N1', 'N3', 'P1', 'K5', 'L3', 'L5', 'M2', 'M4', 'M6', 'N2', 'N4', 'P2']},{'label': 'uI', 'num': 9, 'pin_nums': ['J6', 'K6', 'J7']},{'label': 'uJ', 'num': 10, 'pin_nums': ['N5', 'N6', 'P6', 'P5']}] })])